import datetime
from dataclasses import dataclass
from time import timezone

from IPython.core.release import author
from django.http import HttpResponse
from django.shortcuts import render
from datetime import datetime


# Create your views here.
def index(request):
    return render(request, 'index.html')


def baidu(request):
    return render(request, "baidu.html")


def info(request):
    # 1、普通变量
    name = '知了课堂'
    # 2、字典类型
    book = {'name': "水浒传", 'author': '施耐庵'}
    # 3、列表
    books = [
        {'name': "红楼梦", 'author': '曹雪芹'},
        {'name': "三国演义", 'author': '罗贯中'}
    ]

    context = {
        'name': name,
        'book': book,
        'books': books,
    }

    # 4、对象
    @dataclass
    class Person:
        def __init__(self, name, age):
            self.name = name
            self.age = age

    context = {
        'name': name,
        'book': book,
        'books': books,
        'person': Person('张三', 18)
    }

    return render(request, 'info.html', context=context)


# if标签
def if_view(request):
    age = 19
    context = {'age': age}
    return render(request, 'if.html', context=context)


# for标签
def for_view(request):
    books = [
        {'name': "红楼梦", 'author': '曹雪芹'},
        {'name': "三国演义", 'author': '罗贯中'}
    ]

    # 1、列表
    # context = {
    #     'books': books,
    # }

    # 2、字典
    person = {
        'name': '张三',
        'age': 19,
        'height': 180
    }

    context = {
        'books': books,
        'person': person,
    }

    return render(request, 'for.html', context=context)



def with_view(request):
    books = [
        {'name': "红楼梦", 'author': '曹雪芹'},
        {'name': "三国演义", 'author': '罗贯中'}
    ]
    context = {
        'books': books,
    }
    return render(request, 'with.html', context=context)


def url_view(request):
    books = [
        {'name': "红楼梦", 'author': '曹雪芹'},
        {'name': "三国演义", 'author': '罗贯中'}
    ]
    context = {
        'books': books,
    }
    return render(request,'url.html',context=context)


def filter_view(request):
    greet="Hello world ,Hello Django"
    context = {
        'greet': greet,
        'birthday':datetime.now(),
        'profile':"",
        'h5':'<h2>欢迎来到知了课堂</h2>'
    }
    return render(request,'filter.html',context=context)



def template_form(request):
    greet="Hello world ,Hello Django"
    context = {
        'articles':['小米su7','chatgpt-5发布']
    }
    return render(request,'xfz_index.html',context=context)



def static_view(request):
    return render(request,'static.html')